package utilidades;

public class Pair<T1, T2> implements Comparable<Pair<T1, T2>> {

	public static <T1, T2> Pair<T1, T2> create(T1 p1, T2 p2) {
		return new Pair<T1, T2>(p1, p2);
	}

	private T1 p1;
	private T2 p2;

	private Pair(T1 p1, T2 p2) {
		this.p1 = p1;
		this.p2 = p2;
	}

	public T1 p1() {
		return p1;
	}

	public T2 p2() {
		return p2;
	}

	public void setP1(T1 b1) {
		p1 = b1;
	}

	public void setP2(T2 b2) {
		p2 = b2;
	}

	public boolean equals(Object o) {
		boolean r = false;
		if (o instanceof Pair) {
			Pair<?, ?> o1 = (Pair<?, ?>) o;
			r = p1().equals(o1.p1()) && p2().equals(o1.p2());
		}
		return r;
	}

	public int hashCode() {
		return p1().hashCode() * 31 + p2().hashCode();
	}

	public String toString() {
		return "(" + p1() + "," + p2() + ")";
	}

	public int compareTo(Pair<T1, T2> p) {
		return hashCode() - p.hashCode();
	}

}
